import java.util.Scanner;

// 离最近的斐波那契数距离
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int prior = 0;
        int next = 1;
        while(true) {
            if(prior <= n && next >= n) {
                System.out.println(Math.min((n-prior),(next-n)));
                return;
            }
            int tem = next;
            next = next + prior;
            prior = tem;
        }
    }
}